﻿<script type="text/javascript" language="javascript">
    $(document).ready(function () {    
        var urlPath = "@Request.Url.AbsoluteUri";
        //window.history.replaceState({ "html": "@Request.InputStream", "pageTitle": "Lista de Eventos" }, "", urlPath);     
     });
 </script>

@using System.Globalization
@model PagedList.IPagedList<CultuRAM.Models.Event>


<h4><i class="icon-list" style="margin-top: 3px;"></i> Lista de Eventos</h4>

@if (Model.FirstOrDefault() != null)
{
    <table id="events" class="table table-hover table-striped table-bordered" style="width:100%;">
    <tr style="font-size: 12px">
        <th class="@String.Format(ViewBag.IconSortType)">     
            @Ajax.ActionLink("Tipo", "IndexPvHl", new { sortOrder=ViewBag.TypeSortParm, stringFilter = ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>
        <th class="@String.Format(ViewBag.IconSortTitle)">     
            @*@Html.ActionLink("Título" , "Index", new { sortOrder=ViewBag.TitleSortParm, currentFilter=ViewBag.CurrentFilter })*@
            @Ajax.ActionLink("Título", "IndexPvHl", new { sortOrder=ViewBag.TitleSortParm, stringFilter = ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>
        <th class="@String.Format(ViewBag.IconSortDate)"> 
            @*@Html.ActionLink("Data", "Index", new { sortOrder=ViewBag.DateSortParm, currentFilter=ViewBag.CurrentFilter })*@
            @Ajax.ActionLink("Data", "IndexPvHl", new { sortOrder=ViewBag.DateSortParm, stringFilter=ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>
        <th class="@String.Format(ViewBag.IconSortTime)">
            @*@Html.ActionLink("Hora", "Index", new { sortOrder=ViewBag.TimeSortParm, currentFilter=ViewBag.CurrentFilter})*@
            @Ajax.ActionLink("Hora", "IndexPvHl", new { sortOrder=ViewBag.TimeSortParm, stringFilter=ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>
        <th class="@String.Format(ViewBag.IconSortPlace)">
            @*@Html.ActionLink("Local", "Index", new { sortOrder=ViewBag.PlaceSortParm, currentFilter=ViewBag.CurrentFilter })*@
            @Ajax.ActionLink("Local", "IndexPvHl", new { sortOrder=ViewBag.PlaceSortParm, stringFilter=ViewBag.CurrentFilter},
                             new AjaxOptions
                                 {
                                     UpdateTargetId="tabEvents", 
                                     InsertionMode = InsertionMode.Replace, 
                                     HttpMethod = "GET" 
                                 })
        </th>
        <th class="@String.Format(ViewBag.IconSortEntity)">    
            @*@Html.ActionLink("Entidade", "Index", new { sortOrder=ViewBag.EntitySortParm, currentFilter=ViewBag.CurrentFilter })*@
            @Ajax.ActionLink("Entidade", "IndexPvHl", new { sortOrder=ViewBag.EntitySortParm, stringFilter=ViewBag.CurrentFilter},
                             new AjaxOptions
                                 {
                                     UpdateTargetId="tabEvents", 
                                     InsertionMode = InsertionMode.Replace, 
                                     HttpMethod = "GET" 
                                 })
        </th>
        <th class="@String.Format(ViewBag.IconSortState)">
            @*@Html.ActionLink("Estado", "Index", new { sortOrder=ViewBag.StateSortParm, currentFilter=ViewBag.CurrentFilter })*@ 
            @Ajax.ActionLink("Estado", "IndexPvHl", new { sortOrder=ViewBag.StateSortParm, stringFilter=ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>
        <th class="@String.Format(ViewBag.IconSortPublic)"> 
            @*@Html.ActionLink("Público", "Index", new { sortOrder=ViewBag.PublicSortParm, currentFilter=ViewBag.CurrentFilter })*@
            @Ajax.ActionLink("Público", "IndexPvHl", new { sortOrder=ViewBag.PublicSortParm, stringFilter=ViewBag.CurrentFilter},
                     new AjaxOptions
                         {
                             UpdateTargetId="tabEvents", 
                             InsertionMode = InsertionMode.Replace, 
                             HttpMethod = "GET" 
                         })
        </th>

        @*<th></th>*@
    </tr>

    @foreach (var item in Model)
    {
        <tr id="@item.EventId" style="cursor: pointer">
            <td>
@*                <div class="circleColorType" style="background-color: @item.EventType.Color; text-align:center">
                      @Html.DisplayFor(modelItem => item.EventType.Type) 
                </div>*@
                <span style="color: @item.EventType.Color; font-weight: bold;">
                    @Html.DisplayFor(modelItem => item.EventType.Type) 
                </span>   
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Title)
            </td>
            <td style="text-align: center;">
                @Html.DisplayName(item.StartDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture))
            </td>
            <td style="text-align: center;">
                @Html.DisplayName(item.StartDate.ToString("HH:mm"))
            </td>
            <td>
                @if (item.PropertyValues != null)
                {
                    foreach (var p in item.PropertyValues.Where(x => x.EventPropertyId == 2))
                    {
                        <span>@p.Value </span>
                    } 
                }                    
            </td>
                        <td>
                @Html.DisplayFor(modelItem => item.Entity.Name)
            </td>
            <td style="vertical-align: middle;">
                 @if (item.PropertyValues != null)
                 {
                     foreach (var p in item.PropertyValues.Where(x => x.EventPropertyId == 1))
                     {
                         if (!String.IsNullOrEmpty(p.Value))
                         {
                             switch (p.Value)
                             {
                                 case "Pendente":
                                     <span class="label label-warning"> @p.Value </span>
                                     break;
                                 case "Confirmado":
                                     <span class="label label-success"> @p.Value </span>
                                     break;
                                 case "Realizado":
                                     <span class="label label-info"> @p.Value </span>
                                     break;
                                 case "Cancelado":
                                     <span class="label label-important"> @p.Value </span>
                                     break;
                                 case "Adiado":
                                     <span class="label label-inverse"> @p.Value </span>
                                     break;
                                 default:
                                     <span class="label"> @p.Value </span>
                                     break;
                             }
                         }
                     }
                 }

            </td>
            <td style="text-align: center; vertical-align: middle;">
                @if (item.Public)
                {
                    <span class="label label-success" style="width: 15px"> <i class="icon-eye-open icon-white"></i> </span>
                }
                else
                {
                    <span class="label label-important" style="width: 15px"> <i class="icon-eye-close icon-white"></i> </span>
                }
                @*@Html.DisplayFor(modelItem => item.Public)*@
            </td>
         </tr>
    }

</table>
    <div class="row-fluid pagination-botton-wpadd">
        
        @* Commands *@
        <div id="" class="span6">
@*            @Html.ActionLink("Criar Evento", "Create", null, new { @class = "btn btn-success" })
            @Html.ActionLink("Editar Evento", null, null, new { @class = "btn btn-warning", id = "btnEdit" })
            @Html.ActionLink("Eliminar Evento", null, null, new { @class = "btn btn-danger", id = "btnDel" })*@

            <a id="btnAdd" href="@Url.Action("Create")" class = "btn btn-success"><i class="icon-plus icon-white"></i> Adicionar Evento</a>
            <a id="btnEdit" href="@Url.Action("Edit")" class = "btn btn-warning"><i class="icon-pencil icon-white"></i> Editar Evento</a>
            <a id="btnDel" href="@Url.Action("Delete")" class = "btn btn-danger"><i class="icon-remove icon-white"></i> Eliminar Evento</a>    
        </div>

        <div class="span6">
            @* Pagination *@
            <div >
                <div class="pagination text-right" style="margin: 0;">
                    <ul>
                        @if (Model.HasPreviousPage)
                        {
                            <li>
                                @Ajax.ActionLink("«", "IndexPvHl", new { page = 1, sortOrder=ViewBag.CurrentSort, stringFilter = ViewBag.CurrentFilter},
                                                 new AjaxOptions
                                                     {
                                                         UpdateTargetId="tabEvents", 
                                                         InsertionMode = InsertionMode.Replace, 
                                                         HttpMethod = "GET" 
                                                     }, 
                                                 new { @class = "" })
                            </li> 
                            <li>
                                @Ajax.ActionLink("<", "IndexPvHl", new { page = Model.PageNumber - 1, sortOrder=ViewBag.CurrentSort, stringFilter = ViewBag.CurrentFilter },
                                                 new AjaxOptions
                                                     {
                                                         UpdateTargetId="tabEvents", 
                                                         InsertionMode = InsertionMode.Replace, 
                                                         HttpMethod = "GET" 
                                                     }, 
                                                 new { @class = "" })
                            </li>
                            <li class="">
                                <a href="#" data-original-title="" title="" class="">
                                    Página <b> @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)</b> de <b> @Model.PageCount </b>
                                </a>
                            </li>                 
                        }
                        else
                        {         
                            <li class="disabled"><a href="#" data-original-title="" title="" class="">«</a></li> 
                            <li class="disabled"><a href="#" data-original-title="" title="" class=""><</a></li> 
                            <li class="">
                                <a href="#" data-original-title="" title="" class="disabled">
                                    Página <b> @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)</b> de <b> @Model.PageCount </b>
                                </a>
                            </li>            
                        }
                
                

                        @if (Model.HasNextPage)
                        {

                            <li>
                                @Ajax.ActionLink(">", "IndexPvHl", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, stringFilter = ViewBag.CurrentFilter },
                                                 new AjaxOptions
                                                     {
                                                         UpdateTargetId = "tabEvents",
                                                         InsertionMode = InsertionMode.Replace,
                                                         HttpMethod = "GET"
                                                     },
                                                 new { @class = "" })
                            </li>
                            <li>
                                @Ajax.ActionLink("»", "IndexPvHl", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, stringFilter = ViewBag.CurrentFilter },
                                                 new AjaxOptions
                                                     {
                                                         UpdateTargetId = "tabEvents",
                                                         InsertionMode = InsertionMode.Replace,
                                                         HttpMethod = "GET"
                                                     },
                                                 new { @class = "" })
                            </li>
                        }
                        else
                        {

                            <li class="disabled"><a href="#" data-original-title="" title="" class="disabled">></a></li> 
                            <li class="disabled"><a href="#" data-original-title="" title="" class="disabled">»</a></li>
                        }
                    </ul>
                </div>

            </div>
        </div>

    </div>

}
else
{
    <div class="alert alert-warning" style="padding: 25px">
        Não foram encontrados dados, para o(s) filtro(s) aplicado(s). Tente novamente!</div>
    <br/>
    <a href="@Url.Action("Create")" class = "btn btn-success"><i class="icon-plus icon-white"></i> Adicionar novo Evento</a>
}



 @Scripts.Render("~/bundles/culturam") 